<?php
$path = dirname(__FILE__);
chdir($path);
require_once '../Common/common.php';

class Demo
{
	public function start()
	{
		$MyRedis = new MyRedis();
		$MtCronModel = new MtCronModel();

		while(true){
			$key = sprintf("KCS_QUEUE_%s_SYNC_PRODUCT", "MEITUAN");
			$value = $MyRedis->LPOP($key);

			if(empty($value)){
				continue;
			}

			$data = explode("_", $value);

			$store_id = $data[0];
			$other_category_id = $data[1];
			$product_id = $data[2];

			$req = $MtCronModel->getSyncProductLimit("MEITUAN", $store_id);

			if($req){
				$MtCronModel->syncProduct($store_id, $other_category_id, $product_id);
			}else{
				$MyRedis->RPUSH($key, $value);
			}
		}
	}
}

$Demo = new Demo();
$Demo->start();

?>